#pragma once
#include <cmath>
#include "matrix.h"

template <class T>
T lerp(float x, const T& a, const T& b) { return a + (b - a) * x; }

template <class T>
T lerp2(float x, float y, const T& a, const T& b, const T& c, const T& d) {
    return lerp(y, lerp(x, a, b), lerp(x, d, c));
}

template <class T>
T polar(const T& v) {
        T coord;
        coord[0] = sqrt(v[0]*v[0] + v[1]*v[1]);
        coord[1] = 0.0;
        if (v[0] == 0 && v[1] == 0)
                coord[1] = 0;
        else if (v[0] >= 0)
                coord[1] = asin(v[1]/coord[0]);
        else
                coord[1] = -asin(v[1]/coord[0]) + M_PI;
        return coord;
}

template <class T>
T scalar(const T& v) {
    T coord;
    coord[0] = v[0] * cos(v[1]);
    coord[1] = v[0] * sin(v[1]);
    return coord;
}
